package edu.amm.fanal.methods;

import edu.amm.fanal.api.Coordinates.CoordinatesType;
import edu.amm.fanal.api.Function;
import edu.amm.fanal.api.LebesgueSpace;
import edu.amm.fanal.api.FunctionalSpace.SpaceType;

/**
 * @author Иванов Илья
 * @since 2013-05-18
 *
 */
public class LeastSquaresMethod extends MomentsMethod {
	
	/**
	 * @param coordinatesType Тип координатной системы.
	 */
	public LeastSquaresMethod(CoordinatesType coordinatesType) {
		super(SpaceType.LEBESGUE, coordinatesType);
	}
	
	public String getName() {
		return getMethodName();
	}
	
	protected double getMatrixCoefficient(int i, int j) {
		// aij = (Aej, Aei)
		Function Aej = zeroProblem.applyLeftHandOperator(basis[j]);
		Function Aei = zeroProblem.applyLeftHandOperator(basis[i]);
		
		return ((LebesgueSpace) space).scalarProduct(Aej, Aei);
	}
	
	protected double getRightHandElement(int i) {
		// fi = (f, Aei)
		Function f = zeroProblem.getF();
		Function Aei = zeroProblem.applyLeftHandOperator(basis[i]);
		
		return ((LebesgueSpace) space).scalarProduct(f, Aei);
	}
	
	public static String getMethodName() {
		return "Метод наименьших квадратов";
	}
}